package com.jixiantubu.yueban;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import com.example.jixiantubu.R;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jixiantubu.adapter.Ac_Faqiren_Adapter;
import com.jixiantubu.bean.Ac_Bean;
import com.jixiantubu.util.MyApplication;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;

public class YueBan_MuLu_FaQiRen extends Activity implements OnClickListener {
	ListView ac_faqiren_lst;
	ImageView ac_fqr_back, ac_fqr_img;
	TextView muluTitle, ac_fqr_nikename, ac_ing;
	MyApplication application;
	Ac_Faqiren_Adapter adapter;
	Context context;
	private int number = 1;// 默认第一页
	List<Ac_Bean> list = new ArrayList<Ac_Bean>();
	private String url = "http://" + MyApplication.getIP()
			+ ":8080/Jinnang/YueBan_Middle";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Window window = this.getWindow();
		window.requestFeature(window.FEATURE_NO_TITLE);
		setContentView(R.layout.ac_faqi_ren);
		initViews();
		initData();
	}

	private void initData() {
		adapter = new Ac_Faqiren_Adapter(list, YueBan_MuLu_FaQiRen.this);
		ac_faqiren_lst.setAdapter(adapter);
		// 绑定参数
		RequestParams params = new RequestParams();
		params.addQueryStringParameter("key", "4");
		params.addQueryStringParameter("people", "1");
		HttpUtils httpUtils = new HttpUtils();
		httpUtils.send(HttpMethod.POST, url, params,
				new RequestCallBack<String>() {
					@Override
					public void onFailure(HttpException arg0, String arg1) {
						// 请求失败
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						// 请求成功
						String result = arg0.result;
						Gson gson = new Gson();
						Type type = new TypeToken<List<Ac_Bean>>() {
						}.getType();
						list = gson.fromJson(result, type);
						adapter.setList(list);
						adapter.notifyDataSetChanged();
					}

				});

	}

	private void initViews() {
		muluTitle = (TextView) findViewById(R.id.ac_fqr_title);
		muluTitle.setText("发起的人");
		ac_faqiren_lst = (ListView) findViewById(R.id.ac_fqr_lst);
		ac_fqr_back = (ImageView) findViewById(R.id.ac_fqr_back);
		ac_fqr_back.setOnClickListener(this);
		ac_faqiren_lst.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(YueBan_MuLu_FaQiRen.this,
						YueBan_XiangQing.class);
				intent.putExtra("ac", list.get(arg2));
				startActivity(intent);
			}
		});

	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.ac_fqr_back:
			finish();
			break;

		default:
			break;
		}
	}
}
